'''
Author: caishuyang
Date: 2023-01-08 14:50:05
LastEditors: caishuyang
LastEditTime: 2023-01-08 16:48:56
Description: 
'''

import yaml

class Ball():
    def __init__(self, typename):

        self.classname = 'Ball'
        self.name = typename

        self.r = 5e-3
        self.m = 1e-3
        self.num = 0

        self.x = 0
        self.y = 0
        self.vx = 0
        self.vy = 0
        self.ax = 0
        self.ay = 0

        self.readParam()

    def readParam(self):
        yamlPath = 'config.yaml'

        flag = True
        try:
            f = open(yamlPath, 'r', encoding='utf-8')
        except:
            print('无法打开', yamlPath)
            flag = False
        if flag:
            cont = f.read()
            param = yaml.load(cont, Loader=yaml.FullLoader)
            dic = param[self.classname][self.name]
            self.r = float(dic['r'])
            self.num = float(dic['num'])
            self.m = float(dic['m'])

    def __str__(self):
        return self.name
